<template>
  <form :id="randomFormDownloadId" method="post" target="_blank" >
  </form>
</template>
<script>
export default {
  data() {
    return {
      randomFormDownloadId: 'id_' + Math.random() * 10000000,
      exprotParams: []
    };
  },

  props: {
    exportUrl: '',
    rowId: ''
  },

  methods: {

    doExport(url, data) {

      var formId = this.randomFormDownloadId
      var formEl = document.getElementById(formId);
 
      formEl.action = url 

      while (formEl.hasChildNodes()) {
        formEl.removeChild(formEl.firstChild);
      }

      for (var key in data) {

        var input = document.createElement("input")
        input.setAttribute("type", 'hidden')
        input.setAttribute("name", key)
        
        let v = data[key]

        if(Array.isArray(v)){            
          input.setAttribute("value", JSON.stringify (v))
        }
        else{
          input.setAttribute("value", v)
        }
        formEl.appendChild(input)
      }

      formEl.submit()

    }
    

  }
}

</script>
